#ifndef __GQUEUE_H
#define __GQUEUE_H

#ifdef __cplusplus
extern "C"
{
#endif
#include <stdint.h>
#include <string.h>

#define ANDMOD(n,power)     ((n)&(power-1))

/**
  * @brief  队列数据结构
  */
typedef struct {
    void* base;         //队列buf的地址
    size_t capcity;     //队列容纳数据项个数
    size_t itemSize;    //数据项大小
    size_t head;
    size_t tail;
    uint8_t isEmpty;
    uint8_t isFull;
} gqueue_t;

    
/*判断队列是否为空*/
int gqueue_is_empty(gqueue_t* queue);
/*判断队列是否已满*/
int gqueue_is_full(gqueue_t* queue);
/*获取队列的数据数量*/
size_t gqueue_used_space(gqueue_t* queue);
/*数据入队*/
int gqueue_push(gqueue_t* queue, void* item);
/*多数据入队*/
int gqueue_push_multiple(gqueue_t* queue, void* item, size_t len,size_t* actualLen);
/*数据出队*/
int gqueue_pop(gqueue_t* queue, void* item);
/*多数据出队*/
int gqueue_pop_multiple(gqueue_t* queue, void* item,size_t len);
/*多数据出队,最多len长度*/
int gqueue_pop_multiple_atmost(gqueue_t* queue, void* item,size_t len,size_t* actualLen);
/*队尾数据出队*/
int gqueue_pop_tail(gqueue_t* queue, void* item);
/*查看队首的数据*/
int gqueue_peek(gqueue_t* queue, void* item);
/*查看队首len长度的数据*/
int gqueue_peek_multiple(gqueue_t* queue, void* item,size_t len);
/*查看队首最多len长度的数据*/
int gqueue_peek_multiple_most(gqueue_t* queue, void* item,size_t len,size_t* actualLen);
/*查看队首的数据*/
int gqueue_peek_head(gqueue_t* queue, void* item);
/*查看队尾的数据*/
int gqueue_peek_tail(gqueue_t* queue, void* item);
/*丢弃count数量的数据  ,此函数不检查要丢弃的数量是否越界*/
int gqueue_discard_multiple(gqueue_t* queue,size_t count);
/*清空队列*/
int gqueue_clear(gqueue_t* queue);
/*队列初始化*/
int gqueue_init(gqueue_t* queue, void* base, size_t capcity, size_t size);
#ifdef __cplusplus
}
#endif

#endif



















